package com.yunchang.springboot.mapper.finance;

import com.yunchang.springboot.config.BaseDao;
import com.yunchang.springboot.models.DO.finance.FinanceCaravanDebitCreditRelation;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public interface FinanceCaravanDebitCreditRelationMapper extends BaseDao<FinanceCaravanDebitCreditRelation> {
    /**
     * 新增或更新数据
     */
    int replaceDataList(@Param("financeCaravanDebitCreditRelationList") List<FinanceCaravanDebitCreditRelation> financeCaravanDebitCreditRelationList);

    /**
     * 根据单号和单据类型查找是否有“手工处理”科目的借贷关系数据
     */
    int getManualProcessingDataByRecordIdAndRecordType(@Param("recordId") String recordId, @Param("recordType") int recordType);

    /**
     * 据单号和单据类型查找所有借贷关系数据
     */
    List<FinanceCaravanDebitCreditRelation> getDataByRecordIdAndRecordType(@Param("recordId") String recordId, @Param("recordType") int recordType);

    /**
     * 在指定日期前根据账单类型，关联单号，sku，借贷种类，科目名查找借贷关系数据
     */
    BigDecimal getAmountByRecordTypeRelatedRecordSkuLoanTypeSubjectId(@Param("recordType") int recordType,
                                                                      @Param("relatedRecordNo") String relatedRecordNo,
                                                                      @Param("sku") String sku,
                                                                      @Param("loanType") int loanType,
                                                                      @Param("subjectId") int subjectId,
                                                                      @Param("time") String time);

    /**
     * 根据sku、仓库、关联的订单号和时间去借贷关系表中查对应的借贷关系数据
     */
    List<FinanceCaravanDebitCreditRelation> getDataByDocumentTypeSkuWarehouseRelatedRecordNoTime(@Param("documentType") int documentType,
                                                                                                 @Param("sku") String sku,
                                                                                                 @Param("warehouse") String warehouse,
                                                                                                 @Param("relatedRecordNo") String relatedRecordNo,
                                                                                                 @Param("time") String time);

    /**
     * 查找是否在此之前有这个采购单号的数据
     */
    List<FinanceCaravanDebitCreditRelation> getDataByGroupIdAndTime(@Param("groupId") String groupId, @Param("dataTime") String dataTime);

    /**
     * 根据关联的采购单号去查找之前是否有对应的出入库的借贷关系
     */
    List<FinanceCaravanDebitCreditRelation> getStorageLogDataRelationByGroupIdAndTime(@Param("groupId") String groupId, @Param("dataTime") String dataTime);

    /**
     * 删除对应shipmentId的关联单号且status是未结算状态的借贷关系
     */
    int delDataByShipmentIdAndPlatformSku(@Param("shipmentId") String shipmentId,@Param("platformSku") String platformSku);

    /**
     * 获得对应shipmentId的FBA发货出库的借方科目的数据
     */
    FinanceCaravanDebitCreditRelation getDataByRelatedRecordNoSkuDocumentTypeAndLoanType(@Param("relatedRecordNo") String relatedRecordNo,
                                                                                         @Param("platformSku") String platformSku,
                                                                                         @Param("documentType") int documentType,
                                                                                         @Param("loanType") int loanType,
                                                                                         @Param("sellerId") String sellerId,
                                                                                         @Param("area") String area);

    /**
     * 根据参数获取amount的和
     *
     * @param stockSku
     * @param shipmentId
     * @param subjectId
     * @return
     */
    Double selectSumAmountByStockSkuAndShipmentIdAndSubjectId(String stockSku, String shipmentId, String subjectId);

    /**
     * 根据参数获取skuNum的和
     *
     * @param stockSku
     * @param shipmentId
     * @param subjectId
     * @return
     */
    Integer selectSumSkuNumByStockSkuAndShipmentIdAndSubjectId(String stockSku, String shipmentId, String subjectId);

    /**
     * 根据参数获取 skuNum 和 amount 的和  key为 skuNum  和 amount
     *
     * @param stockSku
     * @param warehouse
     * @param subjectId
     * @return
     */
    Map selectSumSkuNumAndSumAmountByStockSkuAndWarehouseAndSubjectId(String stockSku, String warehouse, String subjectId);

    /**
     * 根据账单时间和是否生成出入库明细获取对应的数据
     *
     * @param dateTime
     * @param isInventoryDetails
     * @param subjectList
     * @return
     */
    List<FinanceCaravanDebitCreditRelation> selectByDataTimeAndIsInventoryDetails(@Param("dateTime") String dateTime, @Param("isInventoryDetails") Integer isInventoryDetails, @Param("subjectList") List<String> subjectList);

    /**
     * 根据financeCaravanDebitCreditRelationList对象集合更新是否生成出入库数据
     *
     * @param financeCaravanDebitCreditRelationList
     * @return
     */
    int updateIsInventoryDetailsByFinanceCaravanDebitCreditRelationList(@Param("financeCaravanDebitCreditRelationList") List<FinanceCaravanDebitCreditRelation> financeCaravanDebitCreditRelationList);

    /**
     * 获得亚马逊每日库存表的最大日期
     *
     * @return
     */
    String getLatestDateFromFInventoryDetails();

    /**
     * 获取没有手动处理的财务数据中最近的一天时间
     *
     * @return
     */
    String getLatestDateWithNoManualProcess();

    /**
     * 根据参数获取amount的和以及skuNum的和
     * @param stockSku
     * @param shipmentId
     * @param subjectId
     * @return
     */
    Map selectSumAmountAndSumSkuNumByStockSkuAndShipmentIdAndSubjectId(String stockSku,String shipmentId,String subjectId);

    /**
     * 根据sku、RelatedRecordNo、subjectId获取amount的和及skuNum的和（RelatedRecordNo = RelatedRecordNo）
     * @param sku
     * @param relatedRecordNo
     * @param subjectId
     * @return
     */
    Map selectSumAmountAndSumSkuNumBySkuAndSingleRelatedRecordNoAndSubjectId(String sku,String relatedRecordNo,String subjectId);

    /**
     *根据sku、RelatedRecordNo、subjectId获取amount的和及skuNum的和（RelatedRecordNo like RelatedRecordNo）
     * @param sku
     * @param relatedRecordNo
     * @param subjectId
     * @return
     */
    Map selectSumAmountAndSumSkuNumBySkuAndMoreRelatedRecordNoAndSubjectId(String sku,String relatedRecordNo,String subjectId);
}